﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Text;

namespace FieldUpdater.Classes
{
    [Serializable()]
    public class FieldAssociation
    {
        #region Properties
        public string ParentFieldName { get; set; }
        public string ChildFieldName { get; set; }
        public string ConnectingFieldName { get; set; }
        public ConnectionTypes ConnectionType { get; set; }
        public string ConnectionTypeString
        {
            get
            {
                return GetConnectionTypeString(this.ConnectionType);
            }
        }
        #endregion

        #region Overrides
        public override string ToString()
        {
            return Global.SerializeObject<FieldAssociation>(this);
        } 
        #endregion

        #region Static Methods
        public static FieldAssociation FromString(string xmlString)
        {
            return Global.DeserializeObject<FieldAssociation>(xmlString);
        }

        public static string GetConnectionTypeString(string connectionType)
        {
            return GetConnectionTypeString((ConnectionTypes)Enum.Parse(typeof(ConnectionTypes), connectionType));
        }
        public static string GetConnectionTypeString(ConnectionTypes connectionType)
        {
            switch (connectionType)
            {
                case ConnectionTypes.SharePointLookup:
                    return "Lookup";
                case ConnectionTypes.Oracle:
                    return "Oracle";
                case ConnectionTypes.DateDay:
                    return "Day in the week";
                default:
                    return connectionType.ToString();
            }
        }
        #endregion
    }
}